package com.chalmers.foa.gamemodel.events.impl;

import java.util.List;

import com.chalmers.foa.gamemodel.events.IEvent;
import com.chalmers.foa.gamemodel.gameobjects.IGameObject;

public class EventSwitch implements IEvent {

	List<IGameObject> objects;
	boolean isActive;
	boolean startState;
	int boundID;

	public EventSwitch(List<IGameObject> _objects, int _boundID,
			boolean _startState) {
		objects = _objects;
		boundID = _boundID;
		startState = _startState;
		reset();
	}

	@Override
	public void switchActive() {
		isActive = !isActive;
		for (IGameObject object : objects)
			object.setAlive(isActive);
	}

	public void switchActiveAtTime(int time) {
		final int _time = time;
		new Thread() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000 / _time);
					switchActive();
				} catch (InterruptedException e) {
				}
			}

		}.start();
	}

	@Override
	public boolean isActive() {
		return isActive;
	}

	@Override
	public void reset() {
		isActive = startState;
		for (IGameObject object : objects)
			object.setAlive(startState);
	}

	@Override
	public int getBoundID() {
		return boundID;
	}

}
